/*
package com.xuecheng.system.interceptor;

import cn.hutool.jwt.JWT;
import com.xuecheng.commons.constants.UserConstants;
import com.xuecheng.commons.enums.ErrorCode;
import com.xuecheng.commons.model.vo.AuthInfo;
import com.xuecheng.commons.utils.AuthInfoHolder;
import com.xuecheng.commons.utils.JwtUtils;
import com.xuecheng.web.exception.BusinessException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.concurrent.TimeUnit;

*/
/**
 * @author HuangYuwu
 * @CreateTime 2022/9/11 09:30
 *//*

@Slf4j
@Component
public class LoginInterceptor implements HandlerInterceptor {
    @Autowired
    private RedisTemplate redisTemplate;

    */
/**
     * 登录校验
     * @param request
     * @param response
     * @param handler
     * @return
     * @throws Exception
     *//*

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        // 1.取出请求头token
        String token = request.getHeader("Authorization");
        // 2.校验token
        Boolean verifyToken = JwtUtils.verifyToken(token);
        if (!verifyToken){
            response.setStatus(401);
            throw new BusinessException(ErrorCode.NOTTOKEN);
        }
        // 3.解析token
        AuthInfo infoFromToken = JwtUtils.getInfoFromToken(token);
        // 4.校验是否过期
        if (!redisTemplate.hasKey(UserConstants.USER_ID+infoFromToken.getUid())){
            response.setStatus(401);
            throw new BusinessException(ErrorCode.NOTTOKEN);
        }
        // 5. 续期
        Long expire = redisTemplate.getExpire(UserConstants.USER_ID + infoFromToken.getUid(), TimeUnit.MINUTES);
        if (expire<30){
            redisTemplate.expire(UserConstants.USER_ID + infoFromToken.getUid(),180,TimeUnit.MINUTES);
        }
        // 6.将authinfo存入threadLocal
        AuthInfoHolder.setAuthInfo(infoFromToken);
        return true;
    }

    */
/**
     * 删除线程
     * @param request
     * @param response
     * @param handler
     * @param ex
     * @throws Exception
     *//*

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        AuthInfoHolder.remove();
    }
}
*/
